﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ISRecord.Model
{
    public class UnitOfWork:IUnitOfWork
    {
        #region "Fields"
        Sender2006Entities context;
        OutboxRepository outboxes;
        #endregion
        #region "Constructor"
        public UnitOfWork()
        {
            context = new Sender2006Entities();
        }
        #endregion
        #region "IUnitOfWork Implementation"
        public RepositoryBase<Outbox> Outboxes
        {
            get
            {
                if (outboxes == null)
                {
                    outboxes =  new OutboxRepository(context);
                }
                return outboxes;
            }
        }

        public void Save()
        {
            try
            {
                context.SaveChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        bool disposed = false;
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    if (context != null)
                    {
                        context.Dispose();
                    }
                }
            }
            disposed = true;
        }
        #endregion

        
    }
}
